﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.DrawingCore;
using System.IO;
using System.DrawingCore.Imaging;
using System.Windows.Media.Imaging;

namespace MyMusicPlay._4._0
{
    /// <summary>
    /// 右键菜单
    /// </summary>
    public class RightMenu : BaseClass
    {
        private MainWindow _main;

        public RightMenu(MainWindow main)
        {
            _main = main;
        }

        public void Initialize()
        { }

        /// <summary>
        /// 创建歌单列表的菜单
        /// </summary>
        public ContextMenu CreateMenuByMusicList(string musicListName)
        {
            ContextMenu contextMenu = new();
            contextMenu.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;

            var menuItem = CreateMenuItem(contextMenu, $"Delete {musicListName}");
            menuItem.Name = musicListName;
            menuItem.Click += _main.DeleteMusicList_click;
            return contextMenu;
        }

        public ContextMenu CreateMenuByMusicPlayingBoard(int key, Music music)
        {
            ContextMenu contextMenu = new();
            contextMenu.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            contextMenu.Loaded += _main.PlayBoardItemMenu_Loaded;
            contextMenu.Closed += _main.PlayBoardItemMenu_Closed;

            var menuItem = CreateMenuItem(contextMenu, $"Delete {music.Name}");
            menuItem.Name = $"PlayBoardMenu_" + key;
            menuItem.Click += _main.PlayBoardItemMenuDel_Click;
            return contextMenu;
        }

        public ContextMenu CreateMenuByProgramMenu()
        {
            ContextMenu contextMenu = new();

            var menuItemByPlaying = CreateMenuItem(contextMenu, $"Playing");
            menuItemByPlaying.Click += _main.PlayingBut_Click;
            var menuItemByFirstMusic = CreateMenuItem(contextMenu, $"Previous");
            menuItemByFirstMusic.Click += _main.PreviousBut_Click;
            var menuItemByLaseMusic = CreateMenuItem(contextMenu, $"Next");
            menuItemByLaseMusic.Click += _main.NextBut_Click;
            var menuItemByShutDown = CreateMenuItem(contextMenu, $"ShutDown");
            menuItemByShutDown.Click += (sender, e) => { _main.Close(); };

            contextMenu.Width = 100;
            return contextMenu;
        }

        #region MusicDisplayList
        //最大宽度[限定在MusicDisplayList中使用]
        public double MaxWidth = 0;
        public ContextMenu CreateMenuByMusicPlayingList()
        {
            ContextMenu contextMenu = new();
            contextMenu.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
            contextMenu.Loaded += _main.MusicListBoxItemMenu_Loaded;

            var menuItem = CreateMenuItem(contextMenu, "");
            menuItem.IsEnabled = false;
            var menuItem01 = CreateMenuItem(contextMenu, "Insert Playing");
            menuItem01.Click += _main.MusicListBoxItemMenu_Click;
            var menuItem02 = CreateMenuItem(contextMenu, "Update Cur Select");
            menuItem02.Click += _main.MusicListBoxItemMenuUpateMusic_Click;
            MaxWidth = contextMenu.Width;
            return contextMenu;
        }
        #endregion

        private MenuItem CreateMenuItem(ContextMenu menu, string name)
        {
            MenuItem menuItem = new();
            menuItem.Header = name;
            menuItem.FontSize = 12;
            menuItem.Height = 24;

            TextBlock textBlock = new() { FontSize = 12 };
            var curWidth = SY_Library.Text.GetDisPlayWidth(name, textBlock.FontFamily, textBlock.FontStyle, textBlock.FontWeight, textBlock.FontStretch, 12);
            menu.Width = (curWidth + 50 > menu.ActualWidth ? curWidth + 50 : menu.ActualWidth);

            menu.Items.Add(menuItem);
            return menuItem;
        }


    }
}
